
#include "view_time_0.h"
#include "app_trace.h"
#include "battery_ctrl.h"
#include "blecom.h"
#include "datetime.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "font/num_font.h"
#include "font_mngr.h"
#include "heart_rate_interface.h"
#include "lfs_file_manager_auto.h"
#include "platform_assert.h"
#include "rtc.h"
#include "sport_his.h"
#include "view_common.h"
#include "view_time_0.inc"
#include "temperature/temperature.h"
#define LOG(fmt, ...) // app_trace_log(fmt "\r\n", ##__VA_ARGS__)

void show_time_0_battery_with_xy(int battery,int x,int y)
{
    uint8_t front_width = 5;
    uint8_t front_spacing = 1;
		disp_draw_user_image_filter_color(x+front_width+front_spacing, y, img_time_0_percentage);

    if (battery < 0)
    {
        battery = 0;
        disp_draw_user_image(x, y, img_time_0_battery_num_TAB[battery]);
    }

    int length = get_num_digit(battery);
    LOG("%d", length);
    for (uint8_t i = 0; i < length; i++)
    {
        disp_draw_user_image_filter_color(x, y, img_time_0_battery_num_TAB[battery % 10]);
        x -= (front_width + front_spacing);
        battery /= 10;
    }
		

}

void show_time_0_battery(int battery)
{
	show_time_0_battery_with_xy(disp_ctrl.com_data.i_temp[7],108,7);
}

void show_time_0_ble_with_xy(bool connect, int x, int y)
{
    if (connect)
    {
        disp_draw_user_image_filter_color(x, y, img_ble_connect);
    }
    else
    {
        disp_draw_user_image_filter_color(x, y, img_ble_disconnect);
    }
}
void show_time_0_ble(bool connect)
{
    show_time_0_ble_with_xy(connect, 3, 0);
}
#if defined(TIME_0_SKIP)
#else


static void view_time_0_time(void)
{
	const uint8_t img_time_0_hour_num_TAB[]=
	{
		FILE_IMG_twbp_hour_44_38_0,
		FILE_IMG_twbp_hour_44_38_1,
		FILE_IMG_twbp_hour_44_38_2,
		FILE_IMG_twbp_hour_44_38_3,
		FILE_IMG_twbp_hour_44_38_4,
		FILE_IMG_twbp_hour_44_38_5,
		FILE_IMG_twbp_hour_44_38_6,
		FILE_IMG_twbp_hour_44_38_7,
		FILE_IMG_twbp_hour_44_38_8,
		FILE_IMG_twbp_hour_44_38_9,
	};
	
	const uint8_t img_time_0_minute_num_TAB[] = 
	{
		FILE_IMG_twbp_min_3_112_0,
		FILE_IMG_twbp_min_3_112_1,
		FILE_IMG_twbp_min_3_112_2,
		FILE_IMG_twbp_min_3_112_3,
		FILE_IMG_twbp_min_3_112_4,
		FILE_IMG_twbp_min_3_112_5,
		FILE_IMG_twbp_min_3_112_6,
		FILE_IMG_twbp_min_3_112_7,
		FILE_IMG_twbp_min_3_112_8,
		FILE_IMG_twbp_min_3_112_9,
	};
	
	_disp_show_flash_img(DISP_LFS_FILE_INDEX_0,32,38,img_time_0_hour_num_TAB[disp_ctrl.com_data.i_temp[3]/10]);
	_disp_show_flash_img(DISP_LFS_FILE_INDEX_1,73,38,img_time_0_hour_num_TAB[disp_ctrl.com_data.i_temp[3]%10]);
	_disp_show_flash_img(DISP_LFS_FILE_INDEX_2,6,112,img_time_0_minute_num_TAB[disp_ctrl.com_data.i_temp[4]/10]);
	_disp_show_flash_img(DISP_LFS_FILE_INDEX_3,47,112,img_time_0_minute_num_TAB[disp_ctrl.com_data.i_temp[4]%10]);
}

static void view_time_0_temperature(void)
{
	float temperature = disp_ctrl.com_data.f_temp[26];
	disp_draw_user_image_filter_color(4,186,img_time_0_temperature_icon);
	show_temperature_float_with_degree(70,192,temperature);
}

static void view_time_0_bloodoxygen(void)
{
	disp_draw_user_image_filter_color(93,3,img_bloodoxygen);
}

void view_time_0_display(void)
{
    view_time_0_time();
    show_time_0_battery_with_xy(disp_ctrl.com_data.i_temp[7],6,10);
		view_time_0_temperature();
	view_time_0_bloodoxygen();
}
#endif
